We arrive to week #6 of Fablab Academy and this week is all about embedded programming. In this week I won't be using any machine like I did last week, but I have a some assignments to complete. So let´s begin with this week journey and see how everything
works out for me.
This week assignmets are:
Group assignments:
Browse through the data sheet for your microcontroller.
Compare the performance and development workflows for other architectures
Individual assignments:
Write a program for a microcontroller development board that you made to:
Interact (with local input &/or output devices)
And communicate (with remote wired or wireless devices)
Extra credit: use different languages &/or development environments
Extra credit: connect external components to the board
What will I need for this week assignments:
Microcontroller board (I'm using week 04. board)
Arduino IDE
Embedded system structure
What is embedded programming?
Embedded systems programming, also known as embedded programming, facilitates the development of consumer-facing devices that don't use conventional operating systems the way that
desktop computers and mobile devices do. Microprocessors and microcontrollers are built into these embedded devices to aid in the performance of a single function or set of related functions.
Common examples of embedded systems include microwaves, smart refrigerators, industrial robots, video consoles and satellites.
Many embedded systems might not have a user interface (UI) if they are programmed to carry out a specific task inside a device such as the computers that control an automobile's tire pressure
monitoring system or antilock brake system. Due to the lack of a human interface, these embedded systems use sensors to monitor specific features and can initiate an automated action in
response to data received from the sensor. Yet, other embedded systems, such as those seen in mobile devices, will have intricate graphical UIs using a touchscreen, LED and button
technologies.
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino hardware to upload
programs and communicate with them.
Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The message area gives feedback
while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error messages and other information. The Arduino Arduino Software (IDE) - connects to the Arduino boards to upload programs and
communicate with them. These sketches are written in the text editor and are saved with the file extension .ino.
Libraries
Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. To use a library in a sketch, select it from the Sketch > Import Library menu. This will insert
one or more #include statements at the top of the sketch and compile the library with your sketch. Because libraries are uploaded to the board with your sketch, they increase the amount of space
it takes up. Some libraries are included with the Arduino software. Others can be downloaded from a variety of sources or through the Library Manager.
The Protoboard, also known as a breadboard, solderless breadboard, or terminal array board, is a type of building platform used to create semi-permanent prototypes of electronic circuits without soldering.
Is simply a board for prototyping or building circuits on. It allows you to place components and connections on the board to make circuits without soldering. The holes in the breadboard take care
of your connections by physically holding onto parts or wires where you put them and electrically connecting them inside the board. The ease of use and speed are great for learning and quick
prototyping of simple circuits. Breadboard circuits are also not ideal for long term use like circuits built on perfboard or PCB, but they also don’t have the soldering, or design and manufacturing
costs (PCBs).
Why do you use a BreadBoard?
A breadboard is handy because you can set up circuits quickly and temporarily to test them and move on to a more permanent arrangement after investigating how it works on the breadboard.
They are great for hobbyists and tinkerers to set up projects as a standalone device or as a peripheral to an Arduino, Raspberry Pi, LaunchPad, BeagleBone, and many other development
boards. They come in many sizes to fit projects large and small. Breadboards are also inexpensive, and the parts that work with them are also typically inexpensive too.
Seeed Studio XIAO is a thumb-sized development board. “XIAO” means tiny, tiny but powerful. All XIAO development boards are empowered by powerful and popular chips, such as SAMD21, nRF52840, and ESP32C3,
it is possible for a wide range of applications. In addition, it is compact and all SMD components are placed on the same side of the board, so designers can easily integrate XIAO into their own boards for
rapid mass production.
Seeed Studio XIAO Series are diminutive development boards, sharing a similar hardware structure, where the size is literally thumb-sized. The code name "XIAO" here represents its half feature "Tiny", and
the other half will be "Puissant". Seeed Studio XIAO ESP32S3 Sense integrates camera sensor, digital microphone and SD card supporting. Combining embedded ML computing power and photography capability, this
development board can be your great tool to get started with intelligent voice and vision AI.
Characteristics:
High-performance:
Incorporate the ESP32S3 32-bit, dual-core, Xtensa processor chip operating up to 240 MHz, mounted multiple development ports, Arduino / MicroPython supported
Ultra low-power:
Detachable OV2640 camera sensor for 1600*1200 resolution, compatible with OV5640 camera sensor, intergating additional digital microphone
Wireless:
Lithium battery charge management capability, offer 4 power consumption model which allows for deep sleep mode with power consumption as low as 14μA
Iot breakthroughs:
Offer 8MB PSRAM and 8MB FLASH, supporting SD card slot for external 32GB FAT memory
Features:
Powerful MCU Board:
Incorporate the ESP32S3 32-bit, dual-core, Xtensa processor chip operating up to 240 MHz, mounted multiple development ports, Arduino / MicroPython supported
Advanced Functionality (for Sense):
Detachable OV2640 camera sensor for 1600*1200 resolution, compatible with OV5640 camera sensor, intergating additional digital microphone
Elaborate Power Design:
Lithium battery charge management capability, offer 4 power consumption model which allows for deep sleep mode with power consumption as low as 14μA
Great Memory for more Possibilities:
Offer 8MB PSRAM and 8MB FLASH, supporting SD card slot for external 32GB FAT memory
Outstanding RF performance:
Support 2.4GHz Wi-Fi and BLE dual wireless communication, support 100m+ remote communication when connected with U.FL antenna
Thumb-sized Compact Design:
21 x 17.5mm, adopting the classic form factor of XIAO, suitable for space limited projects like wearable devices
With low power consumption, ESP32-S3 is an ideal choice for IoT devices in the following areas:
Smart Home
Industrial Automation
Health Care
Consumer Electronics
Smart Agriculture
POS machines
Service robot
Audio Devices
Generic Low-power IoT Sensor Hubs
Generic Low-power IoT Data Loggers
Cameras for Video Streaming
USB Devices
Speech Recognition
Image Recognition
Wi-Fi + Bluetooth Networking Card
Touch and Proximity Sensing
B). Pin Overview
The ESP32-S3 chip integrates multiple peripherals that require communication with the outside world. To keep the chip package size reasonably small, the number of available pins has to be limited. So the only way to route all the incoming and outgoing signals is
through pin multiplexing. Pin muxing is controlled via software programmable registers
All in all, the ESP32-S3 chip has the following types of pins:
Types of pins:
IO pins with the following predefined sets of functions to choose from:
Each IO pin has predefined IO MUX and GPIO functions
Some IO pins have predefined RTC functions
Some IO pins have predefined analog functions
Predefined functions means that each IO pin has a set of direct connections to certain on-chip components. During run-time, the user can configure which component from a predefined set to connect to a certain pin at a certain time via memory mapped registers
Analog pins that have exclusively-dedicated analog functions
Power pins supply power to the chip components and non-power pin
It is quite essential to have some basic parameters of the product. The following table provides information about the characteristics of Seeed Studio XIAO ESP32S3.
5V - This is 5v out from the USB port. You can also use this as a voltage input but you must have some sort of diode (schottky, signal, power) between your external power source and this pin with anode to battery, cathode to 5V pin.
3V3 - This is the regulated output from the onboard regulator. You can draw 700mA
GND - Power/data/signal ground
At each startup or reset, a chip requires some initial configuration parameters, such as in which boot mode to load the chip, voltage of flash memory, etc. These parameters are passed over via the strapping pins. After reset, the strapping
pins operate as regular IO pins. The parameters controlled by the given strapping pins at chip reset are as follows:
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing. The Arduino
software is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux. It it to build low cost scientific instruments, to prove chemistry and physics principles, or to get started with programming and robotics.
"Uno" means one in Italian and was chosen to mark the release of Arduino Software (IDE) 1.0. The Arduino Uno R3 Compatible Board is a microcontroller board which is based on the ATmega328. Arduino Uno has 14 digital input or output pins (where 6 can be used as PWM outputs),
6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button.
Features:
Easy application programming using open source IDE.
Easy to learn Microcontroller using Arduino boards.
Easy application programming using open source IDE
Ready Library for most of the sensors and application modules.
Arduino also simplifies the process of working with microcontrollers, but it offers some advantage for teachers, students, and interested amateurs over other systems:
Advantages:
Inexpensive:
Arduino boards are relatively inexpensive compared to other microcontroller platforms.
Cross-platform:
The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux operating systems. Most microcontroller systems are limited to Windows.
Simple, clear programming environment:
The Arduino Software (IDE) is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well.
Open source and extensible software:
The Arduino software is published as open source tools, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it's based.
Open source and extensible hardware:
The plans of the Arduino boards are published under a Creative Commons license, so experienced circuit designers can make their own version of the module, extending it and improving it.
Arduino Uno is an open-source microcontroller board based on the processor ATmega328P. It has digital I/O pins, analog inputs, USB connection, a power jack, an ICSP header, and a reset button. It
contains all the necessary modules needed to support the microcontroller.
Structure:
Microcontroller:
this is the brain of an Arduino, and is the component that we load programs into. Think of it as a tiny computer, designed to execute only a specific number of things.
USB port:
Used to connect your Arduino board to a computer.
USB to Serial chip:
It helps translating data that comes from e.g. a computer to the on-board microcontroller. This is what makes it possible to program the Arduino board from your computer.
Digital pins:
Pins that use digital logic (0,1 or LOW/HIGH). Commonly used for switches and to turn on/off an LED.
Analog pins:
Pins that can read analog values in a 10 bit resolution (0-1023).
5V / 3.3V pins:
These pins are used to power external components.
GND:
also known as ground, negative or simply -, is used to complete a circuit, where the electrical level is at 0 volt.
VIN:
Stands for Voltage In, where you can connect external power supplies.
Most Arduino boards are designed to have a single program running on the microcontroller. This program can be designed to perform one single action, such as blinking an LED. It can also be designed to execute hundreds of actions in a cycle. The scope varies from
one program to another.
The program that is loaded to the microcontroller will start execution as soon as it is powered. Every program has a function called "loop". Inside the loop function, you can for example:
Loop function:
Read a sensor.
Turn on a light.
Check whether a condition is met.
All of the above.
The speed of a program is incredibly fast, unless we tell it to slow down. It depends on the size of the program and how long it takes for the microcontroller to execute it, but it is generally in microseconds (one millionth of a second).
C). Features
Processor:
ATMega328P
Memory:
AVR CPU at up to 16 MHz
32KB Flash
2KB SRAM
1KB EEPROM
Security:
Power On Reset (POR)
Brown Out Detection (BOD)
Peripherals:
2x 8-bit Timer/Counter with a dedicated period register and compare channels
1x 16-bit Timer/Counter with a dedicated period register, input capture and compare channels
1x USART with fractional baud rate generator and start-of-frame detection
1x controller/peripheral Serial Peripheral Interface (SPI)
1x Dual mode controller/peripheral I2C
1x Analog Comparator (AC) with a scalable reference input
Watchdog Timer with separate on-chip oscillator
Six PWM channels
Interrupt and wake-up on pin change
ATMega16U2 Processor:
8-bit AVR® RISC-based microcontroller)
Memory:
16 KB ISP Flash
512B EEPROM
512B SRAM
1debugWIRE interface for on-chip debugging and programming
In this section i'll make a comparison between the XIAO-ESP32-S3 and the Arduino UNO. I'm going to focus in what I think are both microcontroller features. At this moment I haven't had the opportunity to work
with any of the microcontrollers so this is base on what I have investigate.
XIAO-ESP32-S3
ESP32 has various interfaces for peripherals, like Wi-Fi and Bluetooth, allowing
connectivity. It has numerous GPIO pins and communication interfaces.
It supports various programming languages like C, C++, and Python.
Based on the technical specifications, I think this one is used in advanced projects with higher/powerful
processing capabilities.
It may be one the most popular microcontrollers for more advanced and experienced
users due to its wifi and bluetooth connectivity.
Arduino UNO
It has become one of the most popular microcontroller due to its ease use. It has
several GPIOs and common microcontroller communication interfaces.
Although it has a lower processing power compared to ESP32 it can be use for smaller and simpler projects.
As XIAO-ESP32-S3, Arduino supports C, C++ and microPython and counts with many libraries.
Based on the features that Arduino offers, it can be used for small and simple projects
with lower processing requierements, maybe it's the best option for someone who has
just begun in electronics.
Individual Assignments
Before programming the microcontroller I have to connect the board / arduino to my pc, not at the same time.
A). Programming a microcontroller with ESP32
A1). Blinking led
Now i'm going to use the XIAO-ESP32, in this part i'm testing:
My soldering from week 04.
And the code
Once I have connect the board to my laptop, I follow the next steps:
Now click on file then preferences
Paste the ESP32 board link in the Additional boards manager URLs space on the Arduino IDE and click on Ok.
Then I click on Tools then Boards and then boards manager.
At the left side of the screen click on install the latest version of the ESP32 board.
At this point I waited like 10 - 15 minutes.
Now go to File -- Examples, -- 01. Basics and Blink.
Clic on the Upload button.
Wait for it to compile.
This code is a default example on the Arduino IDE.
Here's a short video of the test:
A2). Led on/off with button
For this second code, im going to use a button to control de LED. The idea is to turn ON/OFF the LED once I press the button. Lets begin with this code and see how well it goes:
I'll explain the code that is shown in the image below:
First I have to declare the pins where I connected the button and the led I want to turn On/Off.
I had to see the diagram from Quentorres and verify.
In my case the button is in D1 and the led in D0.
Next I have to initialize the button, the led and a the state of my button.
I set the variables as off for the actual state.
Then I define which of my variables is input and output.
Before the code starts working I have to indicate the actual state of the button, in this case off (button hasn't been press).
Next I have to initialize the button, the led and a the state of my button.
Here's the video showing the result of the code:
A3). Led on/off introducing text from PC
For the third code, im using my PC to turn on/off the led. The idea is to turn ON/OFF the LED when I type the word "On" or "Off". Lets take a look to the code:
I'll explain the code that is shown in the image below:
First of all, i got this code from the link above. I made some few changes that I will share.
As I did in the other examples, first I have to declare my variables. I use define, the name of the variable and the pin where is connected.
I set the speed transmition, baudrate.
This is one of the few changes I made, the baudrate was at 9600 and I change it to 155200 which is the highest baudrate for ESP32-S3.
It uses serial because i'm using my laptop to turn on/off the led on the pcb board.
Another change I made was adding more text option to turn ONOFF the led.
At first it only worked with "ON/OFF", now it works with lowercase, I thought there was no difference.
Once I write the command the led turns ON/OFF.
Here's the video for this third example:
B). Programming with Arduino UNO
Now for this part I'm using the same examples I use with ESP32 but with Arduino. So lets begin and see how different they are.
Components for the first code, Blinking led, I need to use:
Protoboard
Arduino ONE
LED
330 ohm resistor
jumper wires
B1). Arduino blinking led
This is the first code with arduino. What it does it makes the led blink and you can indicate the blinking time. Code in section B1 is very similar with the code in section A1, I just have to declare the pins where I
connect the led.
The image below shows the code of the Arduino blinking led and the simulation in TinkerCad. So let's explain it:
As I did in the other codes, I define the variable LED and where I connected to the Arduino ONE. In this case I connected to pin 13.
I have to define the led as output and make sure is off.
Then I start the code in a void loop so the code runs over and over.
In this code I decide to change the delay an set it in 2 seconds.
I verify the code.
Finally upload the code to the arduino.
You can see the code for the blinking led in the images and video.
B2). Arduino Led on/off with button
Lets start with the second code with arduino. In this one i'm using a button to turn ON/OFF the led.
Components for the first code, Blinking led, I need to use:
Protoboard
Arduino ONE
LED
330 ohm resistor
jumper wires
button
In the images below you can see the code of the Arduino Led on/off with button and the simulation in TinkerCad. So let's explain it:
First of all I define the variables button, LED and where I connected each one to the Arduino ONE. In this case I connected to pin 3 and 13.
I define some states, initial and last state of the button and initial state of the led.
I declare INPUT / OUTPUT.
Then a comparison between initial and last state of the button.
Then a condition when the button is ON indicating the button has been press.
Finally, changing the state of the button.
You can see in the video what happens while pressing the button.
FYI: In the thinkerCad image I use another pins.
B3). Led on/off introducing text from PC
Lets start with the last code with arduino. AS I did in the third example with ESP32, i'm turning ON/OFF the led with the words ON/OFF.
In the images below you'll see the code in arduino IDE and TinkerCad. Code doesn't change a lot if we compare it to the code in ESP32, sol let's explain it:
Starting with defining the variable LED and where I connected to the Arduino ONE. In this case I connected to pin 13.
Now I set the speed transmision, this time I set it to 9600 and set the led as an output.
The I start the code in a void loop but with serial communication, because its from pc to arduino.
As I did with ESP32, I add on/off text in several ways (uppercase and lowercase).
Verify the code.
Anda condition to set off the led.
I verify code and compile it.
You can see the blinking led in the video.
C). Final comments between ESP32 and Arduino UNO
After I had some experience coding in ESP32 and Arduino ONE and from a very personal point of view I like both of them and can conclude that:
ESP32:
Is a much more powerful microcontroller.
I think it's better for more experience user.
It helps for advanced project that requires much more processing.
To use it, it's necessary to solder it, so if it's a good oportunity to test your skills.
Arduino ONE:
I think it's a very useful way to start projects.
It a good option for unexperience users, but it doesn't mean that experience one won't use it.
If you're starting to getting to know programming and microcontroller is good way to start.
ThinkerCad helps user to learn how to connect components and gives you ways to program. Also it simulates the code and verify any problem before using the real thing.
Coding is similar to ESP32, just a few changes like a explain above and you can have your microcontroller working.
Final part
Files
In this part you can download the files that I use for this 6th week assignments.